package com.xx.xunyou.serviceImpl;

import com.xx.springBootUtil.excption.BaseException;
import com.xx.xunyou.dao.area.XunyouAreaDAO;
import com.xx.xunyou.entity.area.XunyouArea;
import com.xx.xunyou.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @program: xunyou-parent
 * @author: zhl
 * @create: 2019-04-18
 **/
@Service
public class AreaServiceImpl implements AreaService {

    @Autowired
    private XunyouAreaDAO xunyouAreaDAO;


    @Override
    public Integer queryListCountToManager(Map<String, Object> map) {
        return xunyouAreaDAO.queryListCountToManager(map);
    }

    @Override
    public List<Map> queryListToManager(Map<String, Object> map) {
        return xunyouAreaDAO.queryListToManager(map);
    }

    @Override
    public void insert(XunyouArea xunyouArea) {
        String areaCode = xunyouArea.getAreaCode();
        XunyouArea xunyouArea1 = xunyouAreaDAO.selectByPrimaryKey(areaCode);
        if(xunyouArea1!=null){
            throw new BaseException("该区号已经存在！");
        }
        String areaName = xunyouArea.getAreaName();
        XunyouArea xunyouArea2 = xunyouAreaDAO.selectByAreaName(areaName);
        if(xunyouArea2!=null){
            throw new BaseException("该城市已经存在！");
        }
        xunyouAreaDAO.insertSelective(xunyouArea);

    }
}
